package dhbw.GUI.TableModels;

import java.util.ArrayList;

import javax.swing.JOptionPane;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;

import Main.MyController;
import dhbw.Data.Language;

public class TableModelStudent extends AbstractTableModel {

	private ArrayList<EntryStudentLeistungsuebersicht> table = new ArrayList<EntryStudentLeistungsuebersicht>();
	private MyController myc;
	private String[] colNames;

	public TableModelStudent(MyController myc, ArrayList<EntryStudentLeistungsuebersicht> table ) {
		this.myc = myc;
		String[] s1 = { Language.COURSE[this.myc.getLanguage()],
				Language.GRADE[this.myc.getLanguage()],
				Language.POINTS[this.myc.getLanguage()] };
		colNames = s1;
		this.table = table;
	}

	// Used by the JTable object to set the column names
	@Override
	public String getColumnName(int column) {
		return colNames[column];
	}

	private int colCount = 3;

	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return this.colCount;
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return table.size();
	}

	@Override
	/**
	 * Returns an object from the asked cell
	 * @param Row as int, Col as int
	 * @return Object
	 */
	public Object getValueAt(int row, int col) {
		EntryStudentLeistungsuebersicht entry = table.get(row);
		if (col == 0) {
			return entry.getVorlesung();
		}
		if (col == 1) {
			return myc.getNotenspiegel().getNote(entry.getPunkte());
		}
		if (col == 2) {
			return entry.getPunkte();
		}
		return null;
	}
}
